<template>
  <div>
    <div class="title">
      <auth-title @sendBack="$router.back()" text="我的关注"></auth-title>
    </div>
    <ul>
      <li v-for="(item, index) in listArray" :key="index">
        <img class="icon" :src="item.head_img" alt="图片未加载">
        <div class="content-center">
          <span class="username">{{ item.nickname }}</span>
          <i>2019-10-10</i>
        </div>
        <input @click="cancelFollow(item.id)" type="button" value="取消关注">
      </li>
    </ul>
  </div>
</template>

<script>
import authTitle from '@/commonComponent/authTitle.vue'
import myfollowApi from '@/api/myfollow'

export default {
  data() {
    return {

      listArray: []
    }
  },
  created() {
    this.getPageData()
  },
  methods: {
    getPageData() {
      myfollowApi.getPageData().then(res => {
        let resp = res.data
        console.log(resp);
        this.listArray = resp.data

        this.listArray.forEach(item => {
          if(!item.head_img){
            item.head_img = '/static/image/u80.png'
          }else{
            item.head_img = this.$axios.defaults.baseURL + item.head_img
          }
        })
      })
    },
    cancelFollow(id){
      myfollowApi.cancelFollow(id).then(res => {
        console.log(res);
        this.getPageData()
      })
    }
  },
  components: {
    authTitle
  }
}
</script>

<style scoped>
ul {
  margin-top: 8vw;
}
li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6vw 0;
  border-bottom: 1px solid #d7d7d7;
}

li .icon {
  display: flex;
  width: 13vw;
  margin-left: 6vw;
}

.content-center {
  position: absolute;
  display: flex;
  flex-direction: column;
  left: 23vw;
}

.content-center .username {
  margin-bottom: 1.5vw;
}

.content-center i {
  margin-top: 1vw;
  color: #a1abc3;
}

input[type='button'] {
  width: 20vw;
  padding: 2.3vw 1.3vw;
  background-color: #e1e1e1;
  margin-right: 5vw;
  border: none;
  outline: none;
  border-radius: 10vw;
}
</style>
